package com.gzxw.mogublog.utils;

import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.beanutils.BeanUtils;

import java.util.List;
import java.util.Map;

// 类型转换根据类
public class TypeConverUtils {

//1、map转换为object

    public static Object mapToObject(Map<String, Object> map, Class<?> clas) throws Exception {
        if (map == null) return null;
        Object obj = clas.newInstance();
        BeanUtils.populate(obj, map);
        return obj;
    }

    //2、object转换为map
    public static Map<String , List> objectToMap(Object obj) {
        if (obj == null)
            return null;
        return new BeanMap(obj);
    }


}
